package com.strato.i18n.v1_0_0.activator;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

import com.strato.i18n.v1_0_0.discover.ResourceBundleDiscover;

public class Activator implements BundleActivator {

	private static ResourceBundleDiscover discover;
	private static BundleContext bundleContext;
	
	@Override
	public void start(BundleContext context) throws Exception {
		bundleContext=context;
		discover=new ResourceBundleDiscover();
		Bundle[] bundles = context.getBundles();
		for(Bundle bundle:bundles){
			if(bundle.getState()>=Bundle.INSTALLED){
				discover.onInstalled(bundle);
			}
		}
		context.addBundleListener(discover);
	}

	@Override
	public void stop(BundleContext context) throws Exception {
		if(discover!=null){
			context.removeBundleListener(discover);
			discover=null;
		}
		bundleContext=null;
	}

	public static ResourceBundleDiscover getDiscover() {
		return discover;
	}

	public static BundleContext getContext(){
		return bundleContext;
	}
}
